package cn.tx.mq.listener;

import cn.tx.config.rabbitmq.DelayedQueueConfig;
import cn.tx.config.rabbitmq.TtlQueueConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author: 可乐加糖
 * @create: 2023-03-20 15:28
 * @Description:
 */
@Slf4j
@Component
public class DelayedQueueConsumer {

    @RabbitListener(queues = TtlQueueConfig.QUEUE_DEAD)
    public void receiveQueueDead(Message message, Channel channel){
        String msg = new String(message.getBody());
        log.info("当前时间：{}, 接收到的消息为：{}", new Date(), msg);
    }

    @RabbitListener(queues = DelayedQueueConfig.DELAYED_QUEUE)
    public void receiveDelayedQueue(Message message, Channel channel){
        String msg = new String(message.getBody());
        log.info("当前时间：{}, 接收到延时队列的消息为：{}", new Date(), msg);
    }
}
